package com.jplus.handler;

import com.jplus.VO.ResultVO;
import com.jplus.exception.SFUmbrellaException;
import com.jplus.utils.ResultVOUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@ControllerAdvice
@EnableWebMvc
@Slf4j
public class GlobalExceptionHandler {
    /**
     * 所有的异常都抛SFUmbrellaException
     * 然后用这个类来处理这个SFUmbrellaException，往前端返回异常信息
     * @param e
     * @return
     */

    @ExceptionHandler(value = SFUmbrellaException.class)
    @ResponseBody
    public ResultVO<SFUmbrellaException> exception(SFUmbrellaException e) {
        log.error("全局异常处理，信息：{}", e.getMessage());
        return ResultVOUtils.error(0,e.getMessage(), e.getCause());
    }
}
